import 'package:flutter/material.dart';
import 'package:x3_base_package/x3_base_package.dart';
import 'package:x3_business_core/x3_business_core.dart';

class BusinessRetailsOrderHistory extends StatefulWidget {
  final String businessId;

  /// MyUser or DepotUser
  final String queryType;

  const BusinessRetailsOrderHistory({Key key, @required this.businessId, @required this.queryType}) : super(key: key);

  @override
  State<BusinessRetailsOrderHistory> createState() => _BusinessRetailsOrderHistoryState();
}

class _BusinessRetailsOrderHistoryState extends State<BusinessRetailsOrderHistory> with AutomaticKeepAliveClientMixin {
  final BaseRefreshController refreshController = BaseRefreshController();

  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Column(
      children: [
        buildSearchComponent(),
        Expanded(child: buildListContent(context)),
      ],
    );
  }

  Widget buildSearchComponent() {
    return Container(
      height: 40,
      margin: EdgeInsets.only(right: 16, left: 16.0, top: 12),
      decoration: BoxDecoration(borderRadius: BorderRadius.circular(4), border: Border.all(color: Color(0xFFEFEFEF))),
      child: BaseSearchFilterComponent.appBar(
        hintText: '请输入单号搜索',
        onEditingComplete: (String value) => this.refreshController.refresh(params: {'searchKey': value}),
        onClearOut: () => this.refreshController.refresh(params: {'searchKey': ''}),
      ),
    );
  }

  Widget buildListContent(BuildContext context) {
    String inputApi = '';
    if (widget.queryType == 'MyUser') inputApi = '/retail/retaildepots/clerklist/clerk/retailmainandsub';
    if (widget.queryType == 'DepotUser') inputApi = '/retail/retaildepots/depotlist/clerk/retailmainandsub';
    return BaseRefreshComponent(
      path: inputApi,
      controller: refreshController,
      buildItem: (Map<String, dynamic> item, int index) => BusinessRetailsOrderItem(styleItem: item),
    );
  }
}
